<template>
  <div class="bankBox">
    <!-- <x-header :left-options="{backText: ''}">银行卡管理</x-header> -->
    <top :text="'银行卡管理'"></top>
    <div class="bankCont" style="margin-top:40px;">
      <div class="bankDetail" style="position: relative;margin-bottom:45px;" v-for="bank in bankList">
        <div @click="editBank(bank.id,bank.count,bank.name)">
          <img :src="bank.url[0]" alt="" height="120" style="margin-left:-20px">
          <div class="bankName" style="position: absolute;top: 30px;">
            <div style="color:#fff" class="mgL25">开户行:{{bank.name}}</div>
            <div class="bankName mgL25">
              {{bank.count}}
            </div>
          </div>
        </div>
        <div style="    text-align: right;">
          <img src="../../assets/radio.png" alt="" width="18" style="vertical-align: middle;" v-if="bank.defult">
          <span style="display: inline-block;width: 16px;height: 16px;border: 1px solid #999;border-radius: 50%;vertical-align: middle;"
            v-if="!bank.defult" @click.stop="setDefault(bank)"></span>
          <span style="font-size: 13px;color: #fea620" v-if="bank.defult">默认地址</span>
          <span style="font-size: 13px;color: #999;" v-if="!bank.defult" @click.stop="setDefault(bank)">设为默认地址</span>
          <img src="../../assets/removeIcon.png" alt="" width="15" style="vertical-align: middle;margin-left: 20px;" @click.stop="removeBank(bank)">
        </div>
      </div>
    </div>
    <div class="addBankCont">
      <div v-if="bankList.length==0">
        <img src="../../assets/noBank.png" alt="" width="60" height="60" class="noBank">
        <span>您还没有添加添加银行卡，完成绑定后方可支付</span>
      </div>
      <div class="addBank" @click="$router.push({ path: '/main/addBank' })">
        <span class="iconBank1"></span>
        <span class="iconBank2"></span>
        添加银行卡
      </div>
    </div>
    <div>
      <confirm v-model="show" title="" @on-cancel="onCancel" @on-confirm="onConfirm">
        <p style="text-align:center;">确定要设置成默认地址?</p>
      </confirm>
    </div>
  </div>
</template>
<script>
  import { XHeader, Confirm, Group, XSwitch, TransferDomDirective as TransferDom } from 'vux'
  import http from '../../service/http.js'
  import Top from '../../components/common/top.vue'
  import tips from '../../service/tips.js'
  export default {
    data() {
      return {
        bankList: [],
        show: false,
        bank: ''
      }
    },
    mounted() {
      this.getBankList();
    },
    methods: {
      setDefault(bank) {
        this.bank = bank;
        this.show = true;
      },
      onCancel() {
        this.show = false;
      },
      onConfirm() {
        http.post("/user/bank", {
          id: this.bank.id
        }).then((res) => {
          if (res.data.status == 200) {
            tips.tips(res.data.msg);
            this.getBankList();
          }
        })
      },
      getBankList() {
        http.get('/user/bank').then((res) => {
          if (res.data.status == 200) {
            this.bankList = res.data.body;
          }
        })
      },
      editBank(id, count, name) {
        this.$router.push({ path: '/main/addBank?id=' + id + "&count=" + count + "&name=" + name })
      },
      removeBank(bank) {
        http.delete("/user/bank?id=" + bank.id).then((res) => {
          if (res.data.status == 200) {
            tips.tips(res.data.msg);
            this.getBankList();
          }
        })
      }
    },
    components: {
      XHeader,
      Top,
      Confirm,
      Group,
      XSwitch,
    }
  }
</script>
<style lang="less" scoped>
  body {
    background: #f6f6f6;
  }

  .bankBox .vux-header {
    background: #fff;
  }

  .bankBox .mgL25 {
    margin-left: 25px;
  }

  .bankBox .vux-header .vux-header-title {
    line-height: 40px;
    text-align: center;
    font-size: 18px;
    font-weight: 400;
    color: #000;
  }

  .bankBox .vux-header .vux-header-left .left-arrow:before {
    content: "";
    position: absolute;
    width: 12px;
    height: 12px;
    border: 1px solid #000;
    border-width: 1px 0 0 1px;
    -webkit-transform: rotate(315deg);
    transform: rotate(315deg);
    top: 8px;
    left: 7px;
  }

  .bankBox .addBankCont {
    text-align: center;
  }

  .bankBox .addBank {
    width: 215px;
    height: 30px;
    border: 1px dashed #ccc;
    margin: auto;
    color: #fea620;
    border-radius: 10px;
    line-height: 30px;
    position: relative;
    margin-top: 20px;
  }

  .bankBox .iconHaveBank1,
  .bankBox .iconBank1 {
    display: inline-block;
    width: 20px;
    background: #fea620;
    border: 1px solid #fea620;
    position: absolute;
    top: 15px;
    left: 40px;
  }

  .bankBox .iconBank2,
  .bankBox .iconHaveBank2 {
    display: inline-block;
    height: 15px;
    background: #fea620;
    border: 1px solid #fea620;
    position: absolute;
    top: 7px;
    left: 50px;
  }

  .bankBox .iconHaveBank2 {
    left: 120px;
    background: #ccc;
    border: 1px solid #ccc;
  }

  .bankBox .iconHaveBank1 {
    left: 110px;
    background: #ccc;
    border: 1px solid #ccc;
  }

  .bankBox .bankCont {
    padding: 15px;
  }

  .bankDetail {
    height: 110px;
    /* background-image: url('../../assets/pufaBank.png'); */
    border-radius: 10px;
    padding-left: 15px;
    margin-bottom: 10px;
    background-size: 380px;
    margin-bottom: 20px;
  }

  .bankBox .bankDetailBg {
    height: 110px;
    /* background-image: url('../../assets/zgBank.png'); */
    border-radius: 10px;
    padding-left: 15px;
    margin-bottom: 10px;
    background-size: 380px;
  }

  .bankBox .noBank {
    display: block;
    margin: auto;
    margin-bottom: 20px;
  }

  .bankBox .bankName {
    color: #fff;
    padding-top: 10px;
  }

  .bankBox .bankName {
    color: #fff;
  }

  .bankBox .imgIcon {
    vertical-align: middle;
  }

  .bankBox .addHaveBank {
    width: 100%;
    color: #ccc;
    text-align: center;
    border: 1px dashed #ccc;
    border-radius: 5px;
    height: 30px;
    line-height: 30px;
    position: relative;
  }
</style>